using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;

namespace BardsTaleViewer {
  public class SCR_anims {
    public List<List<SCR_element>> _animsElements;

    public SCR_anims (string filename) {
      List<string> lines = new List<string> ();
      using (TextReader tr = File.OpenText (filename)) {
        for (; ; ) {
          string line = tr.ReadLine ();
          if (line == null)
            break;
          lines.Add (line);
        }
      }

      _animsElements = new List<List<SCR_element>> ();
      foreach (string line in lines) {
        List<SCR_element> elements = new List<SCR_element> ();
        MatchCollection matches = Regex.Matches (line, @"#(\d+) d(\d+)", RegexOptions.IgnoreCase);
        foreach (Match match in matches) {
          SCR_element element = new SCR_element (int.Parse (match.Groups [1].Value), int.Parse (match.Groups [2].Value));
          elements.Add (element);
        }
        if (elements.Count != 0)
          _animsElements.Add (elements);
      }
    }

    public SCR_element getAnimElement (int animIndex, int elementIndex) {
      List<SCR_element> elements = _animsElements [animIndex];
      return (elements [(elementIndex + elements.Count) % elements.Count]);
    }
  }
}
